
var grid = "";

$(function() {

	
	var deleteCheck = $("#deleteCheck").val(); //表格权限按钮控制
	var editCheck = $("#editCheck").val(); //表格权限按钮控制
	
	var dtGridColumns = [{
	    id : 'real_name',
	    title : '合伙人姓名',
	    type : 'string',
	    columnClass : 'text-center',
	    headerStyle : 'color:grey;'
	},{
	    id : 'mobile',
	    title : '手机号',
	    type : 'string',
	    columnClass : 'text-center',
	    headerStyle : 'color:grey;'
	},{
	    id : 'idcard',
	    title : '身份证',
	    type : 'string',
	    columnClass : 'text-center',
	    headerStyle : 'color:grey;'
	  
	},{
	    id : 'create_time',
	    title : '资质获得时间',
	    type : 'date',
	    format:'yyyy-MM-dd hh:mm:ss', 
	    otype:'time_stamp_ms', 
	    oformat:'string',
	    columnClass : 'text-center',
	    headerStyle : 'color:grey;'
	},{
	    id : 'grade',
	    title : '等级',
	    type : 'string',
	    columnClass : 'text-center',
	    headerStyle : 'color:grey;',
	    resolution:function(value){
	        if(value==10){
	        	return '村级';
	        }else if(value==11){
	        	return '镇级';
	        }else if(value==12){
	        	return '县级';
	        }else if(value==13){
	        	return '市级';
	        }else if(value==14){
	        	return '省级';
	        }
	    }
	},{
	    id : 'area',
	    title : '管辖区域',
	    type : 'string',
	    columnClass : 'text-center',
	    headerStyle : 'color:grey;'
	},{
			id : 'type',
		    title : '合伙人获得方式',
		    type : 'string',
		    columnClass : 'text-center',
		    headerStyle : 'color:grey;',
		    resolution:function(value){
		        if(value=="white"){
		        	return '白名单';
		        }else if(value=="register"){
		        	return '注册';
		        }
		    }
	},{
	    id : 'operation',
	    title : '操作',
	    type : 'string',
	    columnClass : 'text-center tpl-table-black-operation',
	    headerStyle : 'color:grey;',
	    resolution:function(value, record, column, grid, dataNo, columnNo){
	        var content = '';
	        if(editCheck)
	        content += '<a href="#" onclick="loadPage(\'agentwhite/'+record.agentId+'/select?type=white\');" shiro:hasPermission="agentwhite:edit"> <i class="am-icon-pencil"></i> 编辑</a> ';
	        content += '  ';
	        if(deleteCheck)
	        content += '<a href="#" onclick="delUser('+record.id+');" class="tpl-table-black-operation-del del-btn" shiro:hasPermission="agentwhite:delete"><i class="am-icon-trash"></i> 删除</a>';
	        return content;
	    }
	}];
	
	var dtGridOption = {
		    lang : 'zh-cn',
		    ajaxLoad : true,
		    check : false,
		    checkWidth :'37px',
		    loadURL : 'agentwhite/list',
		    columns : dtGridColumns,
		    gridContainer : 'dtGridContainer',
		    toolbarContainer : 'dtGridToolBarContainer',
		    tools : '',
		    pageSize : 10,
		    pageSizeLimit : [10, 20, 30]
		};
	grid = $.fn.dlshouwen.grid.init(dtGridOption);
	
	grid.load();
});

function search(){
	  grid.pager.startRecord = 0;
	  grid.pager.nowPage = 1;
	  grid.parameters = new Object();
	  grid.parameters['mobile'] = $("#mobile").val();
	  grid.parameters['realName'] = $("#realName").val();
	  grid.parameters['areaKey'] = $("#areaKey").val();
	  grid.refresh(true);
}
function resetPassword(){
	   var rows = grid.getCheckedRecords();
       if (rows.length == 1) {
    	   loadPage('user/'+rows[0].id+'/toRestPassword');
       }else{
    	   layer.msg("你没有选择行或选择了多行数据", {
               icon : 0
           });
       }
}
function delUser(id){
	del("agentwhite/"+id+"/delete",search);
}


function btnDel(){
	   var rows = grid.getCheckedRecords();
    if (rows.length == 1) {
 	   del('user/'+rows[0].id+'/delete',search);
    }else{
 	   layer.msg("你没有选择行或选择了多行数据", {
            icon : 0
        });
    }
}
function btnEdit(){
	   var rows = grid.getCheckedRecords();
    if (rows.length == 1) {
    	loadPage('user/'+rows[0].id+'/select');
    }else{
 	   layer.msg("你没有选择行或选择了多行数据", {
            icon : 0
        });
    }
}

